package com.jili.dynamic;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * ClassName: AroundAdvice
 * Package com.jili.dynamic
 * Description:
 *
 * @Author: 廖继礼
 * @Create: 2025/3/9
 * @Version: v1.0
 */
@Component
//@Aspect
@Slf4j
public class AroundAdvice {

    /**
     * 环绕通知，需要你在通知中，定义目标方法的执行
     *
     * @param joinPoint 目标分法（获取目标方法信息，多一个执行方法）
     * @return 目标方法的返回值
     */
    @Around("com.jili.dynamic.MyPointCut.pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) {
        // 保证目标方法被执行即可
        Object[] args = joinPoint.getArgs();
        log.info("args is {}", args);
        try {
            // 增强代码 before
            log.info("方法开始之前");
            Object result = joinPoint.proceed();
            log.info("方法开始之后");
            log.info("result is {}", result);
            return result;
        } catch (Throwable e) {
            log.error("发生了异常");
            throw new RuntimeException(e);
        }

    }
}
